package com.neuedu.task;

import java.util.Scanner;

/**
 * 分别在控制台输入字符串和子字符串，并计算字符串中子字符串出现的次数。
 */
public class Task03_6 {
    public static void main(String[] args) {
        Test();

    }

    private static void Test() {
        System.out.println("请输入一个字符串：");
        Scanner scanner = new Scanner(System.in);
        String str0 = scanner.nextLine();
        System.out.println("请输入一个子字符串：");
        String str1 = scanner.nextLine();

        String str2 = "";
        int sum = 0;

        for (int i = 0; i < str0.length(); i++) {
            if (str0.charAt(i) == str1.charAt(0)) {
                for (int j = i; j < str1.length(); j++) {
                    str2 = str2 + str0.charAt(j);
                }
                sum++;
                i = i + str2.length() - 1;
            }
        }

        System.out.println("字符串\""+str0+"\"中有"+sum+"个\""+str1+"\"");

    }
}
